package gern;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class TwoWayMap<K, V> {
    private Map<K, V> positiveMap = new HashMap<K, V>();
    private Map<V, K> negativeMap = new HashMap<V, K>();

    public void add(K k, V v) {
        positiveMap.put(k, v);
        negativeMap.put(v, k);
    }

    public K getByValue(V v) {
        if (negativeMap.containsKey(v)) {
            return negativeMap.get(v);
        }
        return null;
    }

    public V getByKey(K k) {
        if (positiveMap.containsKey(k)) {
            return positiveMap.get(k);
        }
        return null;
    }

    public Collection<V> getValues() {
        return positiveMap.values();
    }

    public Collection<K> getKeys() {
        return positiveMap.keySet();
    }
}
